package com.softwareconstruction.service;

import com.softwareconstruction.model.Paper;
import com.softwareconstruction.exception.NoEnoughPapersException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class RandomSelectionStrategy implements SelectionStrategy {
    @Override
    public List<Paper> selectPapers(List<Paper> papers, int requiredCount) throws NoEnoughPapersException {
        if (papers.size() < requiredCount) {
            throw new NoEnoughPapersException("Not enough papers available for selection");
        }
        List<Paper> selected = new ArrayList<>();
        List<Paper> tempPapers = new ArrayList<>(papers);
        Random random = new Random();
        for (int i = 0; i < requiredCount; i++) {
            int index = random.nextInt(tempPapers.size());
            selected.add(tempPapers.remove(index));
        }
        return selected;
    }
}